/**
 * 
 */
package d20chat;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

/**
 * @author Arul Suresh
 *
 * @version 1.1
 */
public class ChatRC {

	protected String filename = ".chatrc";
	
	public HashMap<String, String> aliases;
	
	public boolean boldMathEval;
	
	public ChatRC(D20Chatui theGui, D20Chat theMain) {
        //init objects
		aliases = new HashMap<String, String>();
		
		//init defaults
		boldMathEval = false;
		
		boolean setupFile = (new File(filename)).exists();

        if ( setupFile )
        {
            try
            {
                // Create a buffer for our file to read into
                BufferedReader bin = new BufferedReader(new FileReader(filename));

                // Read each setting
                String line=bin.readLine();
                while(line!=null){
                	if(line.startsWith("#")){
                		line = bin.readLine();
                		continue;
                	}
                		
                	String[] tokens = line.split("[: ,]");
                	
                	try {
						if(tokens[0].equalsIgnoreCase("alias")){
							aliases.put(tokens[1], tokens[2]);
						}else if(tokens[0].equals("set")){
							if(tokens[1].equals("boldmath"))
								boldMathEval = true;
						}else if(tokens[0].equals("unset")){
							if(tokens[1].equals("boldmath"))
								boldMathEval = false;
						}
					} catch (ArrayIndexOutOfBoundsException e) {
						System.err.println("Error: invalid setting in .chatrc");
					}
                	
                	line = bin.readLine();
                }
            } catch (IOException e){
                System.err.println ("Error reading file " + filename);
            }
        }
    }
}